﻿using System;
using System.Net;

namespace WindowsPhoneApplication1.Connectors
{
    public class Connector
    {
        public  static string ApiUrl = "http://api.blip.pl/";
        public static StartNoLoginPanorama Snlp;
        public static SingleStatusPage Ssp;
        public static AfterLoginPivotPage Alpp;
        public static SingleUserPage Sup;


        public static void AppendAuthHeader(HttpWebRequest req)
        {
            string secondHash = AppSettings.Instance.Username + ":" + AppSettings.Instance.Password;

            string based = Base64Encode(secondHash);

            req.Headers[HttpRequestHeader.Authorization] = "Basic " + based;
        }

        private static string Base64Encode(string data)
        {
            try
            {
                byte[] encData_byte = new byte[data.Length];

                encData_byte = System.Text.Encoding.UTF8.GetBytes(data);

                string encodedData = Convert.ToBase64String(encData_byte);

                return encodedData;
            }
            catch (Exception e)
            {
                throw new Exception("Error in base64Encode" + e.Message);
            }
        }
    }
}
